package com.zhen.converter;

import org.springframework.core.convert.converter.Converter;

import java.text.SimpleDateFormat;
import java.util.Date;

public class StringToDateConverter implements Converter<String,Date> {

    private String datePattern;

    public void setDatePattern(String datePattern) {
        this.datePattern = datePattern;
    }

    public Date convert(String s) {
        try{
            SimpleDateFormat dateFormat = new SimpleDateFormat(datePattern);
            return dateFormat.parse(s);
        }catch (Exception e){
            e.printStackTrace();
            System.out.println("日期转化失败");
            return null;
        }
    }
}
